﻿<%@ Page Title="" Language="C#" MasterPageFile="~/UI/Admin/admin.Master" AutoEventWireup="true" CodeBehind="ExtensionManager.aspx.cs" Inherits="Paltop_v0._1.UI.Admin.ExtensionManager" %>
<asp:Content ID="Content3" ContentPlaceHolderID="Header" runat="server"><script src="../../Scripts/JQuery/jquery-1.7.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var jsFunctions = '<%Response.Write(jsFunctionArray);%>';
        jsFunctions = jsFunctions.split(',');
        function ShowAddPart() {
            $('#ShowAddPartBtn').replaceWith('<input id="CloseAddPartBtn" type="button" value="Close add panel" onclick="CloseAddPart()" />');
            $('#addExtensionPart').show();
            var options = '';
            for (var i = 0; i < jsFunctions.length; i++) {
                options += '<option value="' + jsFunctions[i] + '" >' + jsFunctions[i] + '</option>';
            }
            $('#jsFunctionSelectAdd').html(options);
        }
        function CloseAddPart() {
            $('#CloseAddPartBtn').replaceWith('<input id="ShowAddPartBtn" type="button" value="Add Extension" onclick="ShowAddPart()" />');
            $('#addExtensionPart').hide();
        }
        function addExtension() {
            alert('Extension Added!');
        }
        function Edit(id) {
            $('#EditPart').show();
            $('#tr_' + id + ' td').each(function (index) {
                if (index == 1)
                    $('#edit_Title').val($(this).html());
                else if (index == 2) {
                    var selectedVal = $(this).html();
                    var options = '';
                    for (var i = 0; i < jsFunctions.length; i++) {
                        options += '<option value="' + jsFunctions[i] + '" ' + (jsFunctions[i] == selectedVal ? 'selected="selected"' : '') + '>' + jsFunctions[i] + '</option>';
                    }
                    $('#JsFunctionSelect').html(options);
                }
                else if (index == 3)
                    $('#edit_Description')[0].value = $(this).html();
            });
        }
        function disable(id) {

        }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">

    <input id="ShowAddPartBtn" type="button" value="Add Extension" onclick="ShowAddPart()" />
    <div id="addExtensionPart" style="display: none">
        <label>
            Extension Title:</label><input type="text" id="extensionTitleInput" />
        <br />
        <label class = "Admin" style=" width: 200px; height:40px;">
            JS function:</label><select id="jsFunctionSelectAdd"></select>
        <input id="addExtensionBtn" onclick="addExtension()" type="button" value="Add" />
    </div>
    <div id="EditPart"  style="display: none">
    <input value="Close edit part" onclick="javascript:$('#EditPart').hide();" type="button" />
    <br />
    <label>Title:</label><input type="text" value="" id="edit_Title" />
    <br />
    <label>JsFunction:</label><select id="JsFunctionSelect"></select>
    <br />
    <label>Description:</label><textarea id="edit_Description"></textarea>
    <br />
    <input type="button" onclick="saveEdit()" value="Save" />
    </div>
    <div id="ExtensionListPart">
        <table>
            <thead>
                <tr>
                    <th>
                        ID
                    </th>
                    <th>
                        Title
                    </th>
                    <th>
                        JSFunction
                    </th>
                    <th>
                        Description
                    </th>
                    <th>
                        Edit
                    </th>
                    <th>
                        Disable
                    </th>
                </tr>
            </thead>
            <tbody>
                <%Response.Write(ExtensionRow); %>
            </tbody>
        </table>
    </div>
</asp:Content>
